/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.j2meturk.main;

import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;
import javax.microedition.midlet.MIDlet;
import org.j2meturk.types.BUTTON;
import org.j2meturk.ui.Color;

/**
 *
 * @author eray(dot)ince(at)gmail(dot)com
 */
public class Popup extends Canvas {

    private final int TitleHeight = 20;
    private final int ButonHeight = 10;
    private int FontHeight = 20;
    private final int widthSPACE = 5;
    MIDlet m;
    private int w = 0,  h = 0;
    private String title = "",  message = "",  buttontext = "";
    private Font f = null;
    BUTTON btntype = new BUTTON();

    public Popup(String Title, String Message, String ButtonText, BUTTON btnType, MIDlet temp) {
        this.setFullScreenMode(true);
        this.title = Title;
        this.message = Message;
        this.buttontext = ButtonText;
        this.btntype = btnType;
        w = getWidth();
        h = getHeight();
        m = temp;
        f = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_SMALL);
        Display.getDisplay(temp).setCurrent(this);
    }

    private void clear(Graphics g) {
        g.setColor(Color.TRANSPARENT);
        g.fillRect(0, 0, w, h);
        
    }

    private int Box(){
        return TitleHeight + ButonHeight + FontHeight;
    }
    protected void paint(Graphics g) {
        clear(g);
        g.setColor(Color.DK_BLUE);
        
        g.fillRoundRect(widthSPACE, h/2-Box()/2, w-(widthSPACE*2), Box(), 10, 10);
        g.setColor(Color.WHITE);
        g.drawLine(widthSPACE,h/2-Box()/2+TitleHeight, w-widthSPACE, h/2-Box()/2+TitleHeight);
        g.setFont(f);
     //   g.drawString(title, widthSPACE,h/2-Box()/2+TitleHeight, 0|0);
        TextWrap wrap = new TextWrap(g);
        int MessageHeight = wrap.write(g, title, widthSPACE, h/2-Box()/2+TitleHeight, w, f,1);
        
    }
}
